package com.yumeng.config.helper;

import com.yumeng.common.helper.AssertHelper;
import com.yumeng.config.properties.YumengProperties;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 环境帮助类
 *
 * @author wxd
 * @date 2024/5/28 下午3:06
 */
@Component
public class EnvHelper {

    private static String envFlag = null;
    private static String sysFlag = null;

    public static String getEnvFlag() {
        AssertHelper.assertNotBlank(envFlag, "envFlag is null");
        return envFlag;
    }

    public static String getSysFlag() {
        AssertHelper.assertNotBlank(sysFlag, "sysFlag is null");
        return sysFlag;
    }

    @Autowired
    public EnvHelper(YumengProperties yumengProperties){
        envFlag = yumengProperties.getEnvFlag();
        sysFlag = yumengProperties.getSysFlag();
        if (StringUtils.isBlank(envFlag) ||  StringUtils.isBlank(sysFlag)) {
            throw new RuntimeException("EnvHelper 初始化失败");
        }
    }

    /**
     * 运行环境-开发
     * @return
     */
    public static boolean isDev(){
        return "dev".equalsIgnoreCase(getEnvFlag());
    }
    /**
     * 运行环境-生产
     * @return
     */
    public static boolean isProd(){
        return "prod".equalsIgnoreCase(getEnvFlag());
    }
    /**
     * 运行环境-测试
     * @return
     */
    public static boolean isTest(){
        return "test".equalsIgnoreCase(getEnvFlag());
    }
    /**
     * 运行环境-用户演示
     * @return
     */
    public static boolean isUat(){
        return "uat".equalsIgnoreCase(getEnvFlag());
    }


    /**
     * 系统标识-默认
     *
     * @return
     */
    public static boolean isDefault(){
        return "default".equals(getSysFlag());
    }


    /**
     * 系统标识-江苏
     *
     * @return
     */
    public static boolean isJiangSu(){
        return "jiangsu".equals(getSysFlag());
    }
    /**
     * 系统标识-山东
     *
     * @return
     */
    public static boolean isShanDong(){
        return "shandong".equals(getSysFlag());
    }
    /**
     * 系统标识-陕西
     *
     * @return
     */
    public static boolean isShan3Xi(){
        return "shan3xi".equals(getSysFlag());
    }

}
